/**
 * Yolema.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package org.grayrabbit.pay.core.action.transaction;

import java.util.Map;

import org.grayrabbit.web.struts2.GenericAction;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.grayrabbit.pay.core.model.results.GenericsResult;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.grayrabbit.pay.core.model.pages.PageList;
import org.grayrabbit.pay.core.model.entity.system.AppSystem;
import org.grayrabbit.pay.core.model.entity.system.TradeTerminal;
import org.grayrabbit.pay.core.model.entity.transaction.Trade;
import org.grayrabbit.pay.core.model.entity.transaction.TradeRecord;
import org.grayrabbit.pay.core.biz.manager.system.AppSystemManager;
import org.grayrabbit.pay.core.biz.manager.system.TradeTerminalManager;
import org.grayrabbit.pay.core.biz.manager.transaction.TradeManager;
import org.grayrabbit.pay.core.biz.manager.transaction.TradeRecordManager;

/**
 * 
 * 
 * @author liyd
 * @version $Id: TradeRecordAction.java, v 0.1 Thu May 31 14:50:37 CST 2012 liyd Exp $
 */
@Results({
          @Result(name = GenericAction.RELOAD, location = "trade_record_list", type = "redirectAction"),
          @Result(name = GenericAction.INPUT, location = "trade_record-input.vm"),
          @Result(name = GenericAction.LIST, location = "transaction/trade_record-list.vm") })
@InterceptorRefs({ @InterceptorRef(value = "token", params = { "includeMethods", "save" }),
                  @InterceptorRef("login"), @InterceptorRef("defaultStack") })
public class TradeRecordAction extends GenericAction {

    /** serialVersionUID */
    private static final long          serialVersionUID = 1753853900998855088L;

    /** 涓氬姟瀵硅薄manager鎺ュ彛 */
    @Autowired
    private TradeRecordManager         tradeRecordManager;

    @Autowired
    private TradeManager               tradeManager;

    @Autowired
    private AppSystemManager           appSystemManager;

    @Autowired
    private TradeTerminalManager       tradeTerminalManager;

    private Trade                      trade            = new Trade();

    /** 涓氬姟瀹炰綋瀵硅薄 */
    private TradeRecord                tradeRecord      = new TradeRecord();

    /** 涓氬姟瀹炰綋瀵硅薄鍒楄〃 */
    private PageList<TradeRecord>      tradeRecordList;
    private Map<String, AppSystem>     appMap;
    private Map<String, TradeTerminal> terminalMap;



    /**
     * 根据trade_id查询交易变更记录列表
     * 访问URL /get_by_trade_history_id.action
     * @return
     */
    @Action(value = "get_by_trade_id")
    public String listByTradeId() {

        GenericsResult<PageList<TradeRecord>> result = tradeRecordManager
            .queryPageList(tradeRecord);
        GenericsResult<Map<String, AppSystem>> appResult = appSystemManager.findAllMap();
        GenericsResult<Map<String, TradeTerminal>> terminalResult = tradeTerminalManager
            .findAllMap();

        setTrade(tradeManager.getById(trade.getTradeId()).getResultData());
        if (!result.isSuccess()) {
            this.addActionError(result.getResultMsg());
        }
        if (!appResult.isSuccess()) {
            this.addActionError(appResult.getResultMsg());
        }
        if (!terminalResult.isSuccess()) {
            this.addActionError(terminalResult.getResultMsg());
        }
        terminalMap = terminalResult.getResultData();
        appMap = appResult.getResultData();

        tradeRecordList = result.getResultData();
        return LIST;
    }



    /**
     * Getter method for property <tt>tradeRecord</tt>.
     * 
     * @return property value of tradeRecord
     */
    public TradeRecord getTradeRecord() {
        return tradeRecord;
    }

    /**
     * Setter method for property <tt>tradeRecord</tt>.
     * 
     * @param tradeRecord value to be assigned to property tradeRecord
     */
    public void setTradeRecord(TradeRecord tradeRecord) {
        this.tradeRecord = tradeRecord;
    }

    /**
     * Getter method for property <tt>tradeRecordList</tt>.
     * 
     * @return property value of tradeRecordList
     */
    public PageList<TradeRecord> getTradeRecordList() {
        return tradeRecordList;
    }

    /**
     * Setter method for property <tt>tradeRecordList</tt>.
     * 
     * @param districtList value to be assigned to property tradeRecordList
     */
    public void setTradeRecordList(PageList<TradeRecord> tradeRecordList) {
        this.tradeRecordList = tradeRecordList;
    }

    public Map<String, AppSystem> getAppMap() {
        return appMap;
    }

    public void setAppMap(Map<String, AppSystem> appMap) {
        this.appMap = appMap;
    }

    public Map<String, TradeTerminal> getTerminalMap() {
        return terminalMap;
    }

    public void setTerminalMap(Map<String, TradeTerminal> terminalMap) {
        this.terminalMap = terminalMap;
    }

    public Trade getTrade() {
        return trade;
    }

    public void setTrade(Trade trade) {
        this.trade = trade;
    }
}
